﻿/*
*
*公共指令
*
*/

angular.module('jisuStuHome',[])
// 取整数
.filter('to_int', ['$sce',
function ($sce) {
    return function (num) {
        if (num != undefined && num != "" && num != null && num != 0) {
            return parseInt(num);
        } else {
            return 0;
        }
    };
} ])
// 本地缓存
.factory('LS', [function () {
    return {
        setLS: setLS,
        getLS: getLS,
        delLS: delLS
    }
    // 插入本地缓存
    function setLS(key, value) {
        localStorage.setItem(key, base64encode(escape(JSON.stringify(value))));
        return value;
    }
    //  获取本地缓存
    function getLS(key) {
        var res = localStorage.getItem(key);
        if (res == undefined || res == null || res == "")
            return null;
        return JSON.parse(unescape(base64decode(res)));
    }
    // 删除本地缓存
    function delLS(key) {
        localStorage.removeItem(key);
    }

} ])


//配合link:href
.directive('ngLinkhref', function () {
    return {
        priority: 99,   //指令的优先级
        restrict: 'A',
        link: function (scope, element, attr) {
            var attrName = 'xlink:href';
            attr.$observe('ngLinkhref', function (value) {  //检测元素的变化
                if (!value)
                    return;
                attr.$set(attrName, value);
            });
        }
    };
}); 